<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1,user-scalable=no">
</head>
<body>
<div class="content_body">
    <!--let和var对比的块级作用域-->
    <input type="button" value="按钮1"/>
    <input type="button" value="按钮2"/>
    <input type="button" value="按钮3"/>
</div>
<script>
    window.onload = function () {
        var btn = document.getElementsByTagName('input');
        // for (var i = 0; i < btn.length; i++) {
        //     btn[i].onclick = function () {
        //         alert(i);
        //     }
        // }
        for (let i = 0; i < btn.length; i++) {
            btn[i].onclick = function () {
                alert(i);
            }
        }
    }
</script>

</body>
</html>